<template>
  <div id="newestDiv">
    <span id="newestTitle">最新发布政策</span>
    <div class="carousel-wrap">
      <div id="more" @click="$router.push({ path: '/policy/policyList' })">更多+</div>
      <el-carousel
        :interval="4000"
        type="card"
        :autoplay="true"
        height="320px"
        class="carousel"
        @change="changeCarousel"
      >
        <!-- <el-carousel :interval="4000" type="card" :autoplay="true" height="320px" class="carousel" > -->
        <el-carousel-item v-for="(policy, index) in policys" :key="policy.id">
          <div
            :class="
              carouselIndex == index
                ? 'carouselItemSelected carouselItem'
                : 'carouselItem'
            "
            @click.stop="toDetail(policy, index)"
          >
            <div class="policyTitle">
              <!-- <div class="typeName" :style="'background-color: ' + formatLabel(policy.typeName).color">{{formatLabel(policy.typeName).label}}</div> -->
              <div
                :class="
                  carouselIndex == index ? 'typeName' : 'typeName tyactive'
                "
              >
                {{ policy.typeName }}
              </div>
              <!-- 显示浏览量 -->
              <!-- <div>
                <img
                  class="eyeIcon"
                  :src="
                    carouselIndex == index
                      ? require('@/assets/image/newestBar/eye.png')
                      : require('@/assets/image/newestBar/eyeGrey.png')
                  "
                />
                <span style="color: #b6b6b6; font-size: 12px">{{
                  policy.pv
                }}</span>
              </div> -->
            </div>
            <div class="policyMsg ellipsis">
              {{
                policy.releaseTime.replaceAll("-", "/") +
                " | " +
                policy.no
              }}
            </div>
            <div class="policyName">{{ policy.name }}</div>
            <!-- <el-tooltip class="item" effect="dark" :content="policy.name" placement="top-start">
						</el-tooltip> -->
            <div class="policyUnit">
              <span>发文部门：</span>
              <el-tooltip
                class="item"
                effect="dark"
                :content="policy.publishUnit"
                placement="top"
              >
                <span>{{ policy.publishUnit }}</span>
              </el-tooltip>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script>
  import { formatLabel } from "@/utils/util.js";
  import { getPolicyList } from "@/common/api/policy.js";

export default {
  name: "newestBar",
  data() {
    return {
      policys: [],
      carouselIndex: 0,
      titleBgColor: ["#5FCFC3", "#FF6C6B", "#F19450"],
    };
  },
  methods: {
    /**
     * 轮播图变换事件
     * @param e 变换后的轮播图下标
     */
    changeCarousel: function (e) {
      let ns = this;
      ns.carouselIndex = e;
    },
    /**
     * 获取最新政策信息
     */
    async getPolicys() {
      let ns = this;
      ns.policys = [];
      let data = {
        pageSize: 6,
        pageNum: 1,
        sortType: 1,
        sort: 2,
        // status: 2,
      };
      let res = await getPolicyList(data)
      ns.policys = res.rows;
    },
    /**
     * 格式化标签
     * @param label 标签名
     * @return {string|*} 标签名对象
     */
    formatLabel: function (label) {
      return formatLabel(label);
    },
    /**
     * 跳转到详情
     * @param policy 政策对象
     */
    toDetail: function (policy, index) {
      let ns = this;
      ns.carouselIndex = index;
      // if(ns.carouselIndex != index) {
      // 	return
      // }
      ns.$router.push({ path: "/policy/policyDetail", query: { id: policy.id } });
    },
  },
  mounted() {
    let ns = this;
    ns.getPolicys();
  },
};
</script>

<style scoped>
#newestDiv {
  background: url("~@/assets/image/policy/newestBg.png") no-repeat center top;
  /* width: 1200px; */
  height: 500px;
  display: flex;
  align-items: center;
  flex-direction: column;
}

#newestDiv #newestTitle {
  color: #ffffff;
  font-size: 25px;
  font-weight: bold;
  letter-spacing: 20px;
  padding-top: 40px;
  padding-bottom: 20px;
}

.carousel-wrap {
  position: relative;
}

.carousel-wrap #more {
  text-align: right;
  position: absolute;
  color: #a7b2e6;
  top: -40px;
  right: 0px;
  /* margin-left: 1000px; */
}

/* #app {
  text-align: right;
} */

.carousel-wrap #more:hover {
  text-decoration: underline;
  cursor: pointer;
}

#newestDiv .carousel {
  width: 1200px;
}

#newestDiv .carousel .carouselItem {
  height: 300px;
  width: 400px;
  position: relative;
  background: rgba(255, 255, 255, 0.24);
}

#newestDiv .carousel .carouselItem:hover {
  cursor: pointer;
}

#newestDiv .carousel .carouselItem.eyeIcon {
  transition: all 0.2s ease 0s;
}

::v-deep#newestDiv .carousel .el-carousel__arrow {
  top: 150px;
  background-color: rgba(255, 255, 255, 0.2);
}

::v-deep#newestDiv .carousel .el-carousel__arrow:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

::v-deep#newestDiv .carousel .el-carousel__mask {
  opacity: 0;
}

::v-deep#newestDiv .carousel .el-carousel__item {
  display: flex;
  justify-content: center;
}

::v-deep#newestDiv .carousel .el-carousel__indicators--outside {
  margin-top: 12px;
}
::v-deep#newestDiv .carousel .el-carousel__arrow--left {
  left: 0px;
}
::v-deep#newestDiv .carousel .el-carousel__arrow--right {
  right: 0px;
}
#newestDiv .carousel .carouselItemSelected {
  background-color: #ffffff;
  border: 10px solid #abd5ff;
  /* border-radius: 5px; */
  width: 320px;
  background: rgba(255, 255, 255, 1);
}

.policyTitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  margin-right: 20px;
}

.policyTitle .typeName {
  /* background-color: #5FCFC3;
		color: #FFFFFF; */
  background: rgba(252,172,18,1);
  color: #fff;
  padding: 5px 10px;
  font-size: 15px;
}
.policyTitle .tyactive {
  /* background: #a9a5ff;
  color: #225ee4; */
}

.policyMsg {
  /* display: flex; */
  margin-left: 20px;
  margin-top: 20px;
  color: #ffffff;
  font-size: 13px;
  width: 280px;
  text-align: left;
  /* word-break: break-all;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical; */
}

.carouselItemSelected .policyMsg {
  color: #999999;
}

.policyName {
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
  margin: 10px 20px;
  text-align: left;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  line-height: 40px;
  height: 125px;
}

.carouselItemSelected .policyName {
  color: #333333;
}

.carouselItemSelected:hover .policyName {
  color: #045db9;
}

.carouselItem .policyUnit {
  position: absolute;
  bottom: 20px;
  width: calc(100% - 20px);
  text-align: left;
  padding: 10px 10px 0px 10px;
  border-top: 1px solid #eeeeee;
  color: #ffffff;
  font-size: 12px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}

.carouselItemSelected .policyUnit {
  color: #999999;
}

::v-deep .el-carousel__item--card.is-in-stage {
  cursor: default;
}

::v-deep .el-carousel__indicators .el-carousel__indicator .el-carousel__button {
  background-color: #294dc5;
  height: 12px;
  width: 12px;
  border-radius: 12px;
  opacity: 1;
  border: 1px solid #999999;
}

::v-deep .el-carousel__indicators .is-active .el-carousel__button {
  background-color: #ffffff;
}
</style>
